Skip to content

Add packed virtqueue support #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

prakash-shekhar
Copy link

Summary of the PR

Adds support for packed virtqueues, implementing the VirtIO packed virtqueue format alongside the existing split virtqueue support. Packed virtqueues offer improved performance through better cache locality and reduced memory overhead compared to traditional split virtqueues.

Changes:

  1. VringConfigData structure (src/backend.rs):
    - Updated documentation to clearly distinguish between split and packed virtqueue address semantics
    - For packed virtqueues: desc_table_addr becomes the packed descriptor ring, used_ring_addr becomes driver event suppression, avail_ring_addr becomes device event suppression
  2. vhost-user protocol support (src/vhost_user/message.rs):
    - Added RING_PACKED feature flag (bit 34, value 0x4_0000_0000)
    - Added VHOST_VRING_F_PACKED vring flag (bit 1, value 0x2)
    - Implemented packed virtqueue inflight I/O structures (DescStatePacked, QueueRegionPacked)
  3. vhost-kern support (src/vhost_kern/mod.rs):
    - Extended kernel backend to support packed virtqueue address configuration
    - Added handling of packed layout in vring setup
  4. Test coverage:
    - Added test_packed_virtqueue_features() to validate feature flag definitions
    - Added test_packed_vring_addr_validation() to test packed virtqueue address validation/alignment

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

prakash-shekhar and others added 6 commits June 12, 2025 20:55
Signed-off-by: Prakash Shekhar <[email protected]>
Signed-off-by: Prakash Shekhar <[email protected]>
Bump virtio-queue from v0.14.0 to v0.15.0

Bump virtio-bindings from v0.2.1 to v0.2.5

Signed-off-by: Jinank Jain <[email protected]>
Signed-off-by: Prakash Shekhar <[email protected]>
This release upgraded virtio-queue and virtio-bindings to latest
released version.

Signed-off-by: Jinank Jain <[email protected]>
Signed-off-by: Prakash Shekhar <[email protected]>
Copy link
Member

@stefano-garzarella stefano-garzarella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prakash-shekhar please instead of merge main, can you rebase?

Also please write better commit messages with description other than title, explaining the why of changes.

Comment on lines 81 to 84
#[cfg(feature = "vhost-user")]
let is_packed = config_data.flags & VhostUserVringAddrFlags::VHOST_VRING_F_PACKED.bits() != 0;
#[cfg(not(feature = "vhost-user"))]
let is_packed = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a new function for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I'm confused, we are in VhostKernBackend why checking for vhost-user feature?

@@ -386,6 +386,8 @@ bitflags! {
const LOG_ALL = 0x400_0000;
/// Feature flag for the protocol feature.
const PROTOCOL_FEATURES = 0x4000_0000;
/// Feature flag for packed virtqueue support (VIRTIO_F_RING_PACKED, bit 34).
const RING_PACKED = 0x4_0000_0000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a virtio feature or a vhost-user feature?

@@ -79,7 +79,8 @@ pub trait VhostKernBackend: AsRawFd {

// Check if packed ring format is being used
#[cfg(feature = "vhost-user")]
let is_packed = config_data.flags & VhostUserVringAddrFlags::VHOST_VRING_F_PACKED.bits() != 0;
let is_packed =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, please squash them where you add

@@ -3,6 +3,7 @@
## [Unreleased]

### Added
- Add support for packed virtqueues in vhost-user and vhost-kern backends
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the style, e.g. link to the pr, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants